import axios from 'axios'
import common from "./common.js";
import {
  Toast,
  Indicator
} from 'mint-ui'
axios.defaults.headers.post['Content-Type'] = 'application/json'; //请求头
axios.defaults.headers.Accept = 'application/json'; //请求头
axios.defaults.baseURL = '/';
axios.defaults.withCredentials = true;

// post传参序列化
axios.interceptors.request.use((config) => {
  Indicator.open('加载中...');
  return config;
}, (error) => {
  console.log("错误的传参", 'fail');
  return Promise.reject(error);
});

//返回状态判断
axios.interceptors.response.use((res) => {

  Indicator.close();

  if (!res.data) {
    return Promise.reject(res);
  }
  if (res.data.code === 'login') {

  } else if (res.data.code === 'fail') {
    Toast(res.data.message)
    return  
  }

  return res;
}, (error) => {
  Toast('网络错误')
  Indicator.close();
  return Promise.reject(error);
});


export default {
  
}
